package com.kaiwukj.android.ufamily.mvp.ui.page.dynamic.detail;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.constraintlayout.widget.Group;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.app.base.review.BaseMvpActivity;
import com.kaiwukj.android.ufamily.app.constant.ARouterUrlKt;
import com.kaiwukj.android.ufamily.mvp.http.entity.params.CommentParams;
import com.kaiwukj.android.ufamily.mvp.http.entity.params.CommentReplyParams;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.CommentResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.DynamicResult;
import com.kaiwukj.android.ufamily.mvp.ui.adapter.NineGridIvAdapter;
import com.kaiwukj.android.ufamily.mvp.ui.page.dynamic.DynamicContract;
import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

@Route(path = ARouterUrlKt.DynamicDetailUrl)
public class DynamicDetailActivity extends BaseMvpActivity<DynamicPresenter> implements DynamicContract.View {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.smart_refresh_card_detail)
    SmartRefreshLayout refreshLayout;
    @BindView(R.id.qriv_circle_head_photo)
    ImageView ivAvatar;
    @BindView(R.id.tv_circle_nick_name)
    TextView tvNickName;
    @BindView(R.id.tv_user_community)
    TextView tvUserCommunity;
    @BindView(R.id.qbtn_collection)
    Button btnCollection;
    @BindView(R.id.tv_circle_message_content)
    TextView tvMsgContent;
    @BindView(R.id.rv_circle_card_detail_images)
    NineGridView mImageGrid;
    @BindView(R.id.btn_topic)
    Button btnTopic;
    @BindView(R.id.tv_circle_publish_time)
    TextView tvPublishTime;
    @BindView(R.id.group_comment)
    Group groupComment;

    @Autowired
    int dynamicId = -1;
    @Autowired(name = "dynamic")
    DynamicResult mResult;

    private NineGridIvAdapter mGridIvAdapter;

    @OnClick({R.id.container_left})
    void onViewClick(View v) {
        switch (v.getId()) {
            case R.id.container_left:
                onBackPressedSupport();
                break;
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_dynamic_detail;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        tvTitle.setText("动态详情");
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        if(dynamicId>0){
           // loadData();
        }else{
            onGetDynamic(mResult);
        }
    }

    @Override
    public void onFetchDynamic(List<DynamicResult> results) {

    }

    @Override
    public void onGetDynamic(DynamicResult result) {

    }

    @Override
    public void onGetComment(List<CommentResult> results, boolean isChild) {

    }

    @Override
    public void onCommentResult(int id, CommentParams params) {

    }

    @Override
    public void onReplyResult(int parentPos, int id, CommentReplyParams params) {

    }

    private void loadData(DynamicResult result) {
        Glide.with(this)
                .load(result.getHeadImg())
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(ivAvatar);
        tvNickName.setText(result.getUserName());
        tvUserCommunity.setText(result.getCommunityName());

    }

    /**
     * 初始化ImageViwe
     */
    private void initGroupImageAdapter(List<String> imageList) {
        ArrayList<ImageInfo> imageInfo = new ArrayList<>();
        for (int i = 0; i < imageList.size(); i++) {
            ImageInfo info = new ImageInfo();
            info.setThumbnailUrl(imageList.get(i));
            info.setBigImageUrl(imageList.get(i));
            imageInfo.add(info);
        }
        //单张图片的大小
        mGridIvAdapter = new NineGridIvAdapter(this, imageInfo);
        mImageGrid.setSingleImageSize(ScreenUtils.getScreenWidth() - SizeUtils.dp2px(32));
        mImageGrid.setAdapter(mGridIvAdapter);
    }

}
